﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Poem.Application.Services;
using Volo.Abp.Application.Dtos;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;

namespace ConsoleAppAbpNext.Services
{
    public class PoemConsoleService : ITransientDependency
    {
        //private IRepository<Poem.Core.Entities.Poet> _repository;
        //private IUnitOfWorkManager _unitOfWorkManager;

        //public PoemConsoleService(IRepository<Poem.Core.Entities.Poet> repository, IUnitOfWorkManager unitOfWorkManager)
        //{
        //    _repository = repository;
        //    _unitOfWorkManager = unitOfWorkManager;
        //}

        //public void Run()
        //{
        //    using var uow = _unitOfWorkManager.Begin(new AbpUnitOfWorkOptions());
        //    //Poem.Core.Entities.Poet poet = _repository.FirstOrDefault(); // 关联关系，加载关联表，需要include
        //    Poem.Core.Entities.Poet poet = _repository.AsQueryable().Include(t => t.Poems).FirstOrDefault(); // 关联关系，加载关联表，需要include

        //    Console.WriteLine(poet.Name);
        //    Console.WriteLine(poet.Poems.Count);
        //}

        private readonly IPoemAppService _poemAppService;
        public PoemConsoleService(IPoemAppService poemAppService)
        {
            _poemAppService = poemAppService;
        }

        public void Run()
        {
            var res = _poemAppService.GetPagedPoets(new PagedResultRequestDto { MaxResultCount = 5, SkipCount = 0 });
            Console.WriteLine(res.TotalCount);
            foreach (var dto in res.Items)
            {
                Console.WriteLine(dto.Name);
            }
        }
    }
}
